package be.gnx.fogo.application.ui;

import java.util.ResourceBundle;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.ControlAdapter;
import org.eclipse.swt.events.ControlEvent;
import org.eclipse.swt.events.DisposeEvent;
import org.eclipse.swt.events.DisposeListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;

public abstract class AbstractGroup extends Composite {

  private final Group group;

  protected boolean asFamily = false;

  protected AbstractGroup(Composite composite, int style, ResourceBundle resourceBundle) {
    super(composite, style);
    this.setLayout(new FillLayout());
    group = new Group(this, SWT.SHADOW_ETCHED_IN);

    addDisposeListener(new DisposeListener() {
      public void widgetDisposed(DisposeEvent disposeEvent) {
        AbstractGroup.this.widgetDisposed(disposeEvent);
      }
    });

    addControlListener(new ControlAdapter() {
      public void controlResized(ControlEvent controlEvent) {
        AbstractGroup.this.controlResized(controlEvent);
      }
    });

  }

  protected abstract void widgetDisposed(DisposeEvent disposeEvent);

  protected abstract void controlResized(ControlEvent controlEvent);

  protected void resize() {
    group.setBounds(0, 0, getSize().x, getSize().y);
  }

  protected void setText(String string) {
    group.setText(string);
  }

  protected void setAsFamily(boolean asFamily) {
    this.asFamily = asFamily;
  }

  protected Group getGroup() {
    return group;
  }

}
